﻿#pragma once


#include <QDialog>
#include <QPushButton>
#include "QListView"
#include "QStringListModel"
#include "QFileDialog"
#include "QMessageBox"
#include "QApplication"
#include "QVBoxLayout"
#include <QDesktopWidget>
#include <QLibrary>
#include <QApplication>
#include <QLabel>
#include <QComboBox>
#include "QListView"
#include "QStringListModel"
#include "QLineEdit"
#include "QSpinBox"
#include "QDoubleSpinBox"
#include <QSettings>

#include "commonfunction.h"

#include "halcon_opencv.h"

using namespace std;



#include "qt_graphics_view.h"

class FunctionScan :public QDialog
{
public:
    QSettings* m_qsettings;
    Mat m_image ,m_image_show;
    QString m_section   = "";

    QtQGraphicsView* m_view ;



    QLabel* m_qlabel_row1;
    QSpinBox* m_qspinbox_row1;

    QLabel* m_qlabel_row2;
    QSpinBox* m_qspinbox_row2;

    QLabel* m_qlabel_column1;
    QSpinBox* m_qspinbox_column1;

    QLabel* m_qlabel_column2;
    QSpinBox* m_qspinbox_column2;



	QSpinBox * m_qspinbox_standard_size;
	int m_standard_size = 0;


	QDoubleSpinBox * m_qspinbox_ratio;
	double m_ratio = 0;


	
    QSpinBox * m_qspinbox_threshold_gray;
    int m_threshold_gray = 0;

    QSpinBox * m_qspinbox_threshold_error;
    int m_threshold_error = 0;



    QSpinBox* m_qspinbox_dilation_x;
    int m_dilation_x = 0;

    QSpinBox * m_qspinbox_dilation_y;
    double m_dilation_y = 0;

	


    QSpinBox* m_qspinbox_height_min;
    int m_height_min=0;

    QSpinBox* m_qspinbox_height_max;
    int m_height_max=0;




    QSpinBox* m_qspinbox_empty_x;
    int m_empty_x=0;

    QSpinBox* m_qspinbox_empty_y;
    int m_empty_y=0;

	QSpinBox* m_qspinbox_empty_max_x;
	int m_empty_max_x = 0;

	QSpinBox* m_qspinbox_empty_max_y;
	int m_empty_max_y = 0;


    QSpinBox* m_qspinbox_empty_size;
    int m_empty_size=1;


	QPushButton* m_pushbutton_show_orign_image;
    QPushButton* m_pushbutton_detection;
    QPushButton* m_pushbutton_save_parameter;
    QPushButton* m_pushbutton_return;

    QLabel* m_qlabel_message;



    


    HObject m_region_rectangle,m_region_show,m_region_error;
	vector <int> vector_error_index;

	double value_standard=0;

    HObject image_in;
    int Row1, Column1, Row2, Column2;

	double para_min = 1, para_max = 1;

public:
    explicit FunctionScan(QDialog *parent = nullptr, QSettings* qsettings = nullptr,QString section="", int camera_index = 0) ;
    ~FunctionScan() ;
    void detectionImage();
    bool detection( HObject image_in, QString& message);
    void draw( Mat image_in,Mat& image_out);
    void loadParameter();
    void saveParameter();
    bool showDialog();
};
#pragma execution_character_set("utf-8")
